package org.huzhp.oauth.client;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * @Description: oauth 配置类
 * @Author: huzp
 * @CreateDate: 2020/4/3 13:53
 * @Version: 1.0
 */
@ConfigurationProperties("huzhp.oauth2.client")
public class Oauth2Properties {

    public static final String USER_AUTHORIZATION_URI = "/oauth/authorize";
    public static final String ACCESS_TOKEN_URI = "/oauth/token";
    public static final String USERINFO_URI = "/user/me";
    public static final String LOGOUT_URI = "/oauth/logout";

    /**
     * oauth2 server
     */
    private String server;

    /**
     * 客户端地址
     */
    private String client;

    /**
     * client-id
     */
    private String clientId;

    /**
     * client-secret
     */
    private String clientSecret;

    /**
     * redirect-uri
     */
    private String redirectUri;

    /**
     * scope
     */
    private String scope;

    /**
     * login-success-url
     */
    private String successUrl = "/";


    public String getServer() {
        return server;
    }

    public void setServer(String server) {
        this.server = server;
    }

    public String getClient() {
        return client;
    }

    public void setClient(String client) {
        this.client = client;
    }

    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public String getClientSecret() {
        return clientSecret;
    }

    public void setClientSecret(String clientSecret) {
        this.clientSecret = clientSecret;
    }

    public String getRedirectUri() {
        return this.client + this.redirectUri;
    }

    public void setRedirectUri(String redirectUri) {
        this.redirectUri = redirectUri;
    }

    public String getScope() {
        return scope;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    public String getSuccessUrl() {
        return successUrl;
    }

    public void setSuccessUrl(String successUrl) {
        this.successUrl = successUrl;
    }

    public String getLoginUrl() {
        return this.server + USER_AUTHORIZATION_URI + "?client_id=" + this.clientId + "&response_type=code&scope=" + this.scope + "&redirect-uri=" + this.client + this.redirectUri;
    }

    public String getLogoutRedirectUrl() {
        return this.server + LOGOUT_URI + "?callback=" + this.client + this.successUrl;
    }

    public String getAccessTokenUrl() {
        return this.server + ACCESS_TOKEN_URI;
    }

    public String getUserinfoUrl() {
        return this.server + USERINFO_URI;
    }
}
